package com.kfgj.hkp.manager.history.impl;

import com.kfgj.hkp.manager.AbstractManager;
import com.kfgj.hkp.common.context.CurrentContext;
import com.kfgj.hkp.common.dataaccess.mybatis.IMyBatisBaseDao;
import com.kfgj.hkp.common.user.entity.BaseUserEntity;
import com.kfgj.hkp.dao.history.IAddressBookDbDao;
import com.kfgj.hkp.entity.history.AddressBookEntity;
import com.kfgj.hkp.manager.history.IAddressBookManager;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;

/**
 * @Description manager
 * @Auth xpp
 * @Date 2018/12/8
 * @Version 1.0
 */
@Service
public class AddressBookManagerImpl extends AbstractManager<AddressBookEntity> implements IAddressBookManager {


    @Autowired
    private IAddressBookDbDao addressBookDbDao;


    @Override
    protected IMyBatisBaseDao<AddressBookEntity, Long> getMyBatisDao() {
        return this.addressBookDbDao;
    }


    @Override
    public int countByCreateTime() {
        BaseUserEntity userInfo = CurrentContext.getUserInfo();
        //1.11第三层子开关,根据时间来判断,a,本月已经有数据 false,本月没有数据 true
        // 获取当月第一天和最后一天
        SimpleDateFormat formatDay = new SimpleDateFormat("yyyy-MM-dd");
        SimpleDateFormat formatFen = new SimpleDateFormat("YYYY/MM/dd HH:mm:ss.SSS");
        String firstDayStr, nowDayStr;
        // 获取当月的第一天
        Calendar cale = Calendar.getInstance();
        cale = Calendar.getInstance();
        cale.add(Calendar.MONTH, 0);
        cale.set(Calendar.DAY_OF_MONTH, 1);
        firstDayStr = formatDay.format(cale.getTime());
        System.out.println("当月第一天是:"+firstDayStr);
        Date nowDay = new Date();
        nowDayStr = formatFen.format(nowDay);

        Map<String, Object> map = new HashMap<>();
        map.put("createTimeStart", cale.getTime());
        map.put("createTimeEnd", nowDay);
        map.put("empCode",userInfo.getUserCode());
        int i = addressBookDbDao.countByCreateTime(map);
        return i;
    }

}
